package com.example.demo.model;

import lombok.Getter;
import lombok.Setter;

/**
 * 请求响应
 *
 * @author Eric Wu
 * @since 1.8
 * create 2020-06-08
 */
@Getter
@Setter
public class Response<T> {

    public static final String OK_CODE="000";
    public static final String ERROR_CODE = "001";

    private String code;
    private String msg;
    private T data;


    public Response(){

    }

    public Response(String code,String msg,T data){
        this.code= code;
        this.msg = msg;
        this.data = data;
    }

    public Response(String code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public static <T> Response<T> createOkResponse(T data){
        return new Response<T>(OK_CODE,null,data);
    }

    public static <T> Response<T> createErrorResponse(String msg){
        return new Response<T>(ERROR_CODE,msg);
    }
}
